GBML manual / Queues

queue_contains

True if any item in target equals value, false otherwise (including when target is empty). Nothing in target changes, and no item is taken off the front.

Syntax

queue_contains(target, value) -> bool

Arguments

NameType
targetqueue
valueelement

Returns

bool

Description

true if any item in target, a queue, equals value, false otherwise (including when target is empty).

It only looks. Nothing is taken off the front and nothing is added to the back, so the order of the queue does not change. It answers yes or no and never says where the value is.

This is the queue's own name for the question list_contains asks a list, stack_contains asks a stack and set_contains asks a set. Each container uses its own name so it is always clear which kind of thing you are asking.

What counts as equal

Numbers are equal when they are the same number, and text is equal when every letter is the same.

The longer the queue, the longer it takes

The search starts at the front and looks at one item after another until it finds a match, so a queue that holds more takes longer, and a search that finds nothing looks at every item. It is handy for "is this one already waiting" checks before you push another.

What happens in the awkward cases

You do thisWhat happens
search for a value that is not therefalse
search for a value that is there more than oncetrue
search an empty queuefalse
give it a listrefused when checked. A list has its own, list_contains

Example

/// @type {queue<int>}
var waiting = [];
queue_push(waiting, 4);
queue_push(waiting, 8);
var has8 = queue_contains(waiting, 8);    // true
var has99 = queue_contains(waiting, 99);  // false
if (not queue_contains(waiting, 12)) {
    queue_push(waiting, 12);              // only queued if it is not already waiting
}

On the GBA

The same left-to-right search list_contains makes (find, the GBA module's own alias for std::find) over the deque the queue is kept in, front to back - O(n) in how many items target holds. It only answers yes or no; it does not say where the value is.

See also: queue_pushqueue_popqueue_peekqueue_emptylist_containsQueuesData containers